package com.boxuegu.boxueguapiservice.controller;


import com.boxuegu.boxueguapiservice.entity.Chapter;
import com.boxuegu.boxueguapiservice.service.ExercisesService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

import java.util.HashMap;
import java.util.Map;

/**
 * @author Vincent
 */
@RestController
@RequestMapping("/exercises")
public class ExercisesController {
  @Autowired
  private ExercisesService exercisesService;
  
  /**
   * 习题列表
   * @param param 章节编号
   * @return 章节信息及习题列表
   */
  @PostMapping("/findExercisesByChapterId")
  @ResponseBody
  public Map<String, Object> findExercisesByChapterId(@RequestBody Map<String, Object> param) {
    Map<String, Object> map = new HashMap<>();
    int chapterId = (int) param.get("chapterId");
    Chapter chapter = exercisesService.findExercisesByChapterId(chapterId);
    if (chapter != null) {
      map.put("msg", "成功");
      map.put("success", true);
      map.put("chapter", chapter);
    } else {
      map.put("msg", "失败");
      map.put("success", false);
    }
    return map;
  }
}
